//
//  JddRewithdrawCashSecretViewController.m
//  PlayBall
//
//  Created by My Mac JiangDuoDuo on 14-8-21.
//
//

#import "JddRewithdrawCashSecretViewController.h"

@interface JddRewithdrawCashSecretViewController ()

@end

@implementation JddRewithdrawCashSecretViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)back
{
    [self setJddTabBarHidden:YES];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)loadNavBar
{
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:@"设置提款密码"];
        customLab.textAlignment = NSTextAlignmentCenter;
        
        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;
        
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self loadNavBar];
}
-(void) viewWillAppear:(BOOL)animated
{
    [MobClick beginLogPageView:@"reTiKuanMiMa"];
	[MobClick event:@"UserCenter-reSettikuanmima"];

    [self setJddTabBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"reTiKuanMiMa"];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sureXiuGaiClick:(UIButton *)sender {
    
    NSString *oldPayPwd = self.oldPwd.text;
    NSString *firstSecret = self.firstPaypwd.text;
    NSString *secondSecret = self.secondPaypwd.text;
    if ([oldPayPwd length] == 0) {
        [JddCommonFunction messageBoxWithMessage:@"请输入当前提款密码"];
    
    } else if (![firstSecret length] || ![secondSecret length]) {
        [JddCommonFunction messageBoxWithMessage:INFORMATION_NOT_INTACT];

    } else {
        //两次输入长度不一致或内容不一致
        if ([firstSecret length] != [secondSecret length] || ![firstSecret isEqualToString:secondSecret]) {
            [JddCommonFunction messageBoxWithMessage:@"新密码两次输入不一致"];
            //长度低与6位
        } else if ([secondSecret length] < 6) {
            [JddCommonFunction messageBoxWithMessage:@"提款密码长度不能低于6位字符"];
            //长度高与16位
        } else if ([secondSecret length] > 16) {
            [JddCommonFunction messageBoxWithMessage:@"提款密码长度不能高于16位字符"];
        } else {
            [JddCommonFunction setWaitingViewHidden:NO fromController:self];
//            JddQueryWithdrawCashOperation *operation = [[JddQueryWithdrawCashOperation alloc] init];
            ResetWithDrawOpeartion *operation = [[ResetWithDrawOpeartion alloc] init];
            operation.delegate = self;
            operation.oldPw = self.oldPwd.text;
            operation.nnewPw = self.secondPaypwd.text;
            [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
            
        }
    }

}

-(void)ResetWithDrawOpeartionResult:(NSData *)result{
    
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        if ([JddDataParser parseModifyPasswordResult:result]) {
            [JddUserProfile sharedInstance].IsPayPwd = @"1";
            [self back];
            
        }
        [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
    }
}

//- (void)WithdrawCashOperationResult:(NSData *)result
//{
//    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
//    if (result) {
//        if ([JddDataParser parseModifyPasswordResult:result]) {
//            [JddUserProfile sharedInstance].IsPayPwd = self.secondPaypwd.text;
//            [self back];
//            
//        }
//        [JddCommonFunction messageBoxWithMessage:[JddError sharedInstance].message];
//    }
//    
//}

//点击结束事件绑定
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self resignAllResponder:self.view];
}

//放弃所有可能的第一响应 收键盘
-(void)resignAllResponder:(UIView*)parentView
{
    for (UIView *view in parentView.subviews) {
        if ([view isKindOfClass:[UITextField class]]) {
            [view resignFirstResponder];
        }
        else {
            if ([view isKindOfClass:[UIScrollView class]]) {
                [view resignFirstResponder];
            }
            if ([view.subviews count] != 0) {
                [self resignAllResponder:view];
            }
        }
    }
}
@end
